import {createRouter, createWebHistory,createWebHashHistory, RouteRecordRaw} from "vue-router";
import mainChildrens from './modules/main'
import adminlogChildrens from './modules/user'

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: 'root',
    redirect: { name:'login' }
  },{
    path:'/main',
    name:'main',
    redirect:{ name:'home'},
    component: () => import('@/layout/menurouter.vue'),
    children: mainChildrens
  },{
    path:'/tools',
    name:'tools',
    component: () => import('@/layout/onlyrouter.vue'),
  },{
    path:'/user',
    name:'user',
    redirect:{ name:'login'},
    component: () => import('@/layout/onlyrouter.vue'),
    children: adminlogChildrens
  }
]

const router = createRouter({
  history: createWebHistory(),//createWebHashHistory()
  routes
})

import store from '../store'
import { getStora } from '@/utils/localstore'
router.beforeEach(async (to,from,next)=>{
  // const toname = to.name
  // const { token } = store.getters
  // if((!toname || !token) && toname!='login')
  //   next({name:'login'})
  next()
})
router.afterEach((to)=>{
  let { name,meta:{ title }}= to
  document.title = title || 'PROJECT_NAME'
})


export default router;
